extends ../main

block append body
    div#suppList.panel.box-shadow-none.content-header
        div.panel-body
            div.col-md-12
                h3.animated.fadeInLeft 系统管理
                p.animated.fadeInDown
                    | 系统管理&nbsp;
                    span.fa-angle-right.fa
                        | &nbsp;供货商管理
    div.col-md-12.top-20.padding-0
        div.col-md-12
            div.panel
                div.panel-body
                    div#toolbar.btn-group
                        button#btn_add.btn.btn-default(type="button")
                            span.glyphicon.glyphicon-plus(aria-hidden="true") 新增
                        button#btn_edit.btn.btn-default(type="button")
                            span.glyphicon.glyphicon-pencil(aria-hidden="true") 修改
                        button#btn_del.btn.btn-default(type="button")
                            span.glyphicon.glyphicon-remove(aria-hidden="true") 审核不通过
                        button#btn_check.btn.btn-default(type="button")
                            span.glyphicon.glyphicon-check(aria-hidden="true") 审核
                    table#suppTable


block append footer
    script(type="text/javascript").
        $(function () {
            var app = new Vue({
                el:"#suppList",
                data:{

                },
                methods:{
                    init:function () {
                        var columns = [{
                            checkbox: true
                        }, {
                            field: 'suppName',
                            width: '15%',
                            title: '供货商名称'
                        }, {
                            field: 'suppAddress',
                            width: '20%',
                            title: '供货商地址'
                        }, {
                            field: 'suppUserName',
                            width: '15%',
                            title: '联系人'

                        }, {
                            field: 'suppTelephone',
                            width: '15%',
                            title: '联系电话'
                        }, {
                            field:'suppChargeRatio',
                            width: '5%',
                            title: '收费比例',
                            formatter: function (value, row, index) {
                                return value/100+'%';
                            }

                        }, {
                            field: 'suppWechat',
                            width: '17%',
                            title: '微信号'

                        }, {
                            field: 'state',
                            width: '17%',
                            title: '状态',
                            formatter: function (value, row, index) {
                                switch (value) {
                                    case 1:
                                        return "生效";
                                        break;
                                    case 0:
                                        return "审核不通过"
                                        break;
                                    case 3:
                                        return "待审核"
                                        break;
                                    default:
                                        return "-";
                                        break;
                                }
                            }

                        }, {
                            field: 'createTime',
                            width: '10%',
                            title: '注册时间',
                            formatter: function (value, row, index) {
                                var date = new Date(value);
                                return moment(date).format("LLL");
                            }

                        }];
                        var tableInit = zxlib.datatable("suppTable","id","/manager/sys/getSuppList",columns);
                        console.log(tableInit);
                        tableInit.init();

                        var oButtonInit = new ButtonInit();
                        oButtonInit.Init();
                    }
                }
            });

            app.init();
        });

        var ButtonInit = function () {
            var oInit = new Object();

            oInit.Init = function () {
                //初始化页面上面的按钮事件
                $('#btn_add').click(function () {
                    location.href = '/manager/sys/addSupp';
                });

                $('#btn_edit').click(function () {
                    var a = $('#suppTable').bootstrapTable('getSelections');

                    if (a.length > 1) {
                        zxlib.showAlert("warning", "数据选择过多，请重新选择");
                        return;
                    } else if (a.length <= 0) {
                        zxlib.showAlert("warning", "请选择数据");
                        return;
                    } else {
                        var id = a[0].id;
                        location.href = "/manager/sys/addSupp?id=" + id;
                    }
                });

                $('#btn_del').click(function () {
                    zxlib.showModel('失败？', '确定审核失败么？', function () {
                        var a = $('#suppTable').bootstrapTable('getSelections');
                        var ids = [];
                        for (var i = 0; i < a.length; i++) {
                            ids.push(a[i].id);
                        }

                        if (ids.length <= 0) {
                            zxlib.showAlert("warning", "请选择数据", 1000, function () {
                                zxlib.closeModel();
                            });
                            return;
                        }

                        zxlib.fpost("/manager/sys/delSupp", {'ids': JSON.stringify(ids)}, function (data) {
                            zxlib.closeModel();
                            if (data.code == "0") {
                                zxlib.showAlert("success", "删除成功", 1000, function () {
                                    $('#suppTable').bootstrapTable('refresh', {silent: true});
                                });
                            } else {
                                zxlib.showAlert("error", "删除失败");
                            }
                        });
                    });
                });

                $('#btn_check').click(function () {
                    zxlib.showModel('审核', '确定审核么？', function () {
                        var a = $('#suppTable').bootstrapTable('getSelections');
                        var ids = [];
                        for (var i = 0; i < a.length; i++) {
                            ids.push(a[i].id);
                        }

                        if (ids.length <= 0) {
                            zxlib.showAlert("warning", "请选择数据", 1000, function () {
                                zxlib.closeModel();
                            });
                            return;
                        }

                        zxlib.fpost("/manager/sys/checkSupp", {'ids': JSON.stringify(ids)}, function (data) {
                            zxlib.closeModel();
                            if (data.code == "0") {
                                zxlib.showAlert("success", "审核成功", 1000, function () {
                                    $('#suppTable').bootstrapTable('refresh', {silent: true});
                                });
                            } else {
                                zxlib.showAlert("error", "审核失败");
                            }
                        });
                    });
                });
            };

            return oInit;
        };
